package com.iot.iotplus.controller;

import com.iot.iotplus.base.Result;
import com.iot.iotplus.entity.MqttUser;
import com.iot.iotplus.entity.Tenant;
import com.iot.iotplus.service.TenantService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

@RestController
@RequestMapping("/tenant")
@CrossOrigin
public class TenantController {
    @Autowired
    private TenantService tenantService;

    @PostMapping("/login")
    public Result<?> login(@RequestBody Map<String, Object> tmap) {
        //,String password,String phoneNumber,String code
        String username = (String) tmap.get("username");
        String password = (String) tmap.get("password");
        String phoneNumber = (String) tmap.get("phoneNumber");
        String code = (String) tmap.get("code");
        return tenantService.login(username, password, phoneNumber, code);
    }

    @PostMapping("/register")
    public Result<?> register(@RequestBody Tenant tenant) {
        return tenantService.register(tenant);
    }

    @PostMapping("/get")
    public Result<?> getTenant(@RequestBody Map<String,String> map) {
        return tenantService.getTenant(map.get("tenantId"));
    }
}
